<template>
<div>
  <div v-if="path == '/modify'" class="header" unselectable="on">
    <div class="head_total">
      <span class="name">修改密码</span>
    </div>
  </div>
  <div class="form_box">
    <p>修改密码</p>
    <el-form :model="form" ref="Form" label-width="55px" class="form">
      <el-form-item
        prop="mobile"
        label="账号"
      >
        <el-input v-model="form.mobile" :disabled="path=='/modify'"></el-input>
      </el-form-item>
      <el-form-item
        prop="pwd"
        label="新密码"
      >
        <el-input type="password" v-model="form.pwd"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="login" type="primary" @click="modify()">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>

<script>
  import { pwdEdi } from '../../apis/api.js'
export default {
  data() {
    return {
      path: '/forget',
      form: {
        mobile: '',
        pwd: ''
      }
    }
  },
  methods: {
    modify() {
      console.log(this.form)
      this.form.securityCode = '';
      pwdEdi(this.form).then(res => {
        this.$message({
          message: '密码设置成功，即将跳转登录页面',
          type: 'success',
          duration: 980
        });
        setTimeout(() => {
          sessionStorage.clear();
          this.$router.replace('/login')
        }, 1000)
      })
    }
  },
  mounted() {
    console.log(this.$route.path)
    this.path = this.$route.path;
    if(this.$route.path == '/modify') {
      this.form.mobile = sessionStorage.getItem('mobile')
    }
  }
}
</script>

<style scoped>
  .form_box {
    max-width: 350px;
    margin: 80px auto 0;
    overflow: hidden;
    padding: 5px 30px 5px 25px;
    background: rgba(255, 255, 255, .3);
    border-radius: 20px;
  }
  .form_box>p {
    font-size: 18px; font-weight: 600; margin-bottom: 40px;
  }
  .login {
    width: 200px;
  }
  .btns {
    display: flex;
    justify-content: flex-end;
    line-height: 20px;
  }
  a {
    font-size: 14px;
    color: #409eff;
    text-decoration: none;
  }
</style>
